#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

/*

int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                      void *(*start_routine) (void *), void *arg);
*/

// pthread_attr_t attr;
// int pthread_attr_init(pthread_attr_t *attr);
// int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
// int pthread_attr_destroy(pthread_attr_t *attr);

// int pthread_detach(pthread_t thread);
// pthread_t pthread_self(void);

void *start_routine(void *arg)
{
    pthread_detach(pthread_self()); // 设置了线程的分离属性
    // sleep(3);
    printf("子线程 %d  线程号是%lu\n", *((int *)arg), pthread_self());
}

int main()
{
    int count = 1;
    printf("main 单个进程 的主线程\n");

    while (1)
    {
        // 创建一个线程
        pthread_t thread;
        int res = pthread_create(&thread, NULL, start_routine, &count);
        printf("res=%d  thread=%lu\n", res, thread);
        if (res != 0)
        {
            printf("创建线程失败\n");
            break;
        }
        count++;
    }

    return 0;
}
